/* LiteSQL
 *
 * By Tero Laitinen
 *
 * See LICENSE for copyright information. */

#ifndef _sqlite3_except_hpp
#define _sqlite3_except_hpp
#include <iostream>
#include <string>

namespace sqlite
{
/** base class for exceptions */
class Except
{
private:
    std::string msg;
public:
    Except(std::string m)  : msg(m) {}
    friend std::ostream &operator<<(std::ostream &os, const Except &e)
    {
        os << e.msg;
        return os;
    }
};
/** exception thrown when a record is not found */
class NotFound : public Except
{
public:
    NotFound(std::string s="") : Except("NotFound: "+s) {}
};
/** exception thrown when database cannot be accessed */
class DatabaseError : public Except
{
public:
    DatabaseError(std::string m) : Except("DatabaseError: "+m) {}
};
/** exception thrown when SQL statement cannot be executed */
class SQLError : public Except
{
public:
    SQLError(std::string m) : Except("SQLError: "+m) {}
};
/** exception thrown when backend produces internal error */
class InternalError : public Except
{
public:
    InternalError(std::string m) : Except("InternalError: " +m) {}
};
/** exception thrown when backend cannot allocate memory */
class MemoryError : public Except
{
public:
    MemoryError(std::string m) : Except("Allocation failed: "+m) {}
};
/** exception thrown when database (disk) is full */
class InsertionError : public Except
{
public:
    InsertionError(std::string m) : Except("Database full: "+m) {}
};
/** exception thrown when  违反了约束条件SQLITE_CONSTRAINT */
class ConstraintError : public Except
{
public:
    ConstraintError(std::string m) : Except("ConstraintError: "+m) {}
};
/** exception thrown when none of other exceptions match */
class UnknownError : public Except
{
    // handles the rest
public:
    UnknownError(std::string m) : Except("UnknownError: "+m) {}
};


}
#endif
